package znyl.nursing.job;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import znyl.nursing.service.IContractService;

@Component
@Slf4j
public class ContractJob {

    @Autowired
    private IContractService contractService;

    /**
     * 每天凌晨1点执行：更新“待生效且开始时间≤当前时间”的合同状态为“已生效”
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void updateContractStatus() {
        log.info("合同状态定时任务开始执行");
        try {
            contractService.updateContractStatus();
            log.info("合同状态定时任务执行完成");
        } catch (Exception e) {
            log.error("合同状态定时任务执行失败", e); // 捕获异常，避免任务中断
        }
    }
}